package com.example.informationEntry.service.impl;

import com.example.informationEntry.dao.NaAdmissionTypeDao;
import com.example.informationEntry.entity.NaAdmissionType;
import com.example.informationEntry.service.NaAdmissionTypeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 入学类型表(NaAdmissionType)表服务实现类
 *
 * @author makejava
 * @since 2019-04-08 11:20:34
 */
@Service("naAdmissionTypeService")
public class NaAdmissionTypeServiceImpl implements NaAdmissionTypeService {
    @Resource
    private NaAdmissionTypeDao naAdmissionTypeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param admissionId 主键
     * @return 实例对象
     */
    @Override
    public NaAdmissionType queryById(String admissionId) {
        return this.naAdmissionTypeDao.queryById(admissionId);
    }

    /**
     * 查询多条数据
     *
     * @param studentAdmissionType 入学信息类型中文释义
     * @return 对象列表
     */
    @Override
    public List<NaAdmissionType> queryAllByName(String studentAdmissionType) {
        return this.naAdmissionTypeDao.queryAllByName(studentAdmissionType);
    }

    /**
     * 查询多条数据
     *
     * @param naAdmissionType 实例对象
     * @return list集合
     */
    @Override
    public List<NaAdmissionType> queryAll(NaAdmissionType naAdmissionType){
        return this.naAdmissionTypeDao.queryAll(naAdmissionType);
    }

    /**
     * 新增数据
     *
     * @param naAdmissionType 实例对象
     * @return 实例对象
     */
    @Override
    public NaAdmissionType insert(NaAdmissionType naAdmissionType) {
        this.naAdmissionTypeDao.insert(naAdmissionType);
        return naAdmissionType;
    }

    /**
     * 修改数据
     *
     * @param naAdmissionType 实例对象
     * @return 实例对象
     */
    @Override
    public NaAdmissionType update(NaAdmissionType naAdmissionType) {
        this.naAdmissionTypeDao.update(naAdmissionType);
        return this.queryById(naAdmissionType.getAdmissionNumber());
    }

    /**
     * 通过主键删除数据
     *
     * @param admissionId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String admissionId) {
        return this.naAdmissionTypeDao.deleteById(admissionId) > 0;
    }

    /**
     * k id    v name
     *
     * @return 规整后的数据
     */
    @Override
    public Map<String ,String > queryNumberToName(){
        Map<String ,String > resultMap = new HashMap<>();
        List<NaAdmissionType> list = this.queryAll(new NaAdmissionType());
        for (NaAdmissionType type : list) {
            resultMap.put(type.getAdmissionNumber(),type.getStudentAdmissionType());
        }
        return resultMap;
    }
}